package com.flymobi.mshop.view;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.widget.TextView;
import com.flymobi.mshop.R;

public class TextViewExt extends TextView {
	private int lineColor;

	/**
	 * @return the lineColor
	 */
	public int getLineColor() {
		return lineColor;
	}

	/**
	 * @param lineColor
	 *            the lineColor to set
	 */
	public void setLineColor(int lineColor) {
		this.lineColor = lineColor;
		invalidate();
	}

	/**
	 * @return the lineSize
	 */
	public float getLineSize() {
		return lineSize;
	}

	/**
	 * @param lineSize
	 *            the lineSize to set
	 */
	public void setLineSize(float lineSize) {
		this.lineSize = lineSize;
		requestLayout();
		invalidate();
	}

	private float lineSize;

	@Override
	protected void onDraw(Canvas canvas) {
		super.onDraw(canvas);
		/* ������ɫ�����ƾ��� */
		Paint mPaint = new Paint();
		mPaint.setColor(lineColor);
		canvas.drawLine(0, this.getHeight() / 2, this.getWidth(), this
				.getHeight() / 2, mPaint);
	}

	public TextViewExt(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
	}

	public TextViewExt(Context context, AttributeSet attrs) {
		super(context, attrs);
		// TypedArray��һ�����������context.obtainStyledAttributes��õ����Ե�����
		// ��ʹ����ɺ�һ��Ҫ����recycle����
		// ���Ե������styleable�е����+��_��+�������
		TypedArray array = context.obtainStyledAttributes(attrs,
				R.styleable.TextViewExt);
		lineColor = array
				.getColor(R.styleable.TextViewExt_lineColor, 0XFF000000); // �ṩĬ��ֵ������δָ��
		lineSize = array.getDimension(R.styleable.TextViewExt_lineSize, 1);
		array.recycle(); // һ��Ҫ���ã�������ε��趨����´ε�ʹ�����Ӱ��
	}

	public TextViewExt(Context context) {
		super(context);
	}

}
